//
//  SISSHousingProjectViewController.m
//  SISSAPP
//
//  Created by 袁应荣 on 2018/9/14.
//  Copyright © 2018年 优房网. All rights reserved.
//

#import "SISSHousingProjectViewController.h"

@interface SISSHousingProjectViewController ()<SDCycleScrollViewDelegate>

/// 图片轮播
@property (weak, nonatomic) SDCycleScrollView *cycleScrollView;
/// 图片分页
@property (weak, nonatomic) UILabel *pageLabel;

/// 图片链接数组 
@property (strong, nonatomic) NSArray *imagesURLStrings;

@end

@implementation SISSHousingProjectViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

#pragma mark - UI
- (void)setupSubviews {
    [super setupSubviews];
    
    // 网络加载 --- 创建带标题的图片轮播器
    SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage imageNamed:@"图片加载占位符"]];
    cycleScrollView.autoScroll = NO;
    cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
    cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleNone;
    cycleScrollView.itemDidScrollOperationBlock = ^(NSInteger currentIndex) {
        
        self.pageLabel.text = [NSString stringWithFormat:@" %@/%@ ",@(currentIndex + 1),@(self.imagesURLStrings.count)];
    };
    [self.containerView addSubview:cycleScrollView];
    self.cycleScrollView = cycleScrollView;

    UILabel *pageLabel = [[UILabel alloc] init];
    pageLabel.backgroundColor = [UIColor colorWithWhite:0.8 alpha:0.5];
    pageLabel.textColor = [UIColor whiteColor];
    pageLabel.text = [NSString stringWithFormat:@" %@/%@ ",@(1),@(self.imagesURLStrings.count)];
    pageLabel.textAlignment = NSTextAlignmentCenter;
    pageLabel.layer.cornerRadius = 10;
    pageLabel.layer.masksToBounds = YES;
    [cycleScrollView addSubview:pageLabel];
    self.pageLabel = pageLabel;
    
          
}

#pragma mark - 约束
- (void)initConstraint {
    [super initConstraint];
    
    CGFloat margin = 8.0;
    CGFloat buttonHeight = 44.0;
    WeakSelf
    [self.cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(weakSelf.containerView);
        make.top.equalTo(weakSelf.containerView).offset(margin);
        if (weakSelf.imagesURLStrings.count > 0) {
            make.height.mas_equalTo(20 * margin);
        } else {
            make.height.mas_equalTo(20 * margin);
//            make.height.mas_equalTo(0);
        }
    }];
    
    [self.pageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf.cycleScrollView).offset(-2 * margin);
        make.width.mas_equalTo(6 * margin);
        make.bottom.equalTo(weakSelf.cycleScrollView).offset(-margin);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
